package com.devshephard.jucks.lock.CustomSpinLock;

import java.util.concurrent.TimeUnit;

public class TestMySpinLick {

    public static void main(String[] args) throws InterruptedException {
        SpinLockDemo lockDemo = new SpinLockDemo();

        new Thread(()->{
            lockDemo.myLock();

            try{
                TimeUnit.SECONDS.sleep(3);
            }catch (Exception e){
                e.printStackTrace();
            }finally {
                try {
                    TimeUnit.SECONDS.sleep(3);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                lockDemo.myUnLock();
            }

        },"A").start();

        TimeUnit.SECONDS.sleep(1);

        new Thread(()->{
            lockDemo.myLock();

            try{
                TimeUnit.SECONDS.sleep(1);
            }catch (Exception e){
                e.printStackTrace();
            }finally {
                lockDemo.myUnLock();
            }

        },"B").start();


        /*new Thread(()->{
            lockDemo.myLock();

            try{
                TimeUnit.SECONDS.sleep(1);
            }catch (Exception e){
                e.printStackTrace();
            }finally {
                lockDemo.myUnLock();
            }

        },"C").start();

        new Thread(()->{
            lockDemo.myLock();

            try{
                TimeUnit.SECONDS.sleep(1);
            }catch (Exception e){
                e.printStackTrace();
            }finally {
                lockDemo.myUnLock();
            }

        },"D").start();*/
    }

}
